<?php
class Shell_Command_Dbg extends Shell_Command_Abstract_CommandBase implements Shell_Command_Abstract_IShellCommand
{
	public function __construct()
	{
		parent::__construct();
		$this->NAME = "d";	
		//$this->NAME = "d%%";
	}
	
//*************************************************************************************************
	public function execute($arguments) 
	{			
		
		$userInput = "";
		
		while($userInput != 'exit')
		{
			$userInput = Core_IO::readUserInput('%debug: ',true);
			$this->parseInput($userInput);
		}
		/*
		$fs = Core_Registry::read(Enum_RegistryItems::FILE_SYSTEM);	
		echo "\n\n\n============================================================\n";
		echo ($fs);
		echo "\n============================================================\n\n\n";
		*/
	}
	
	
//******************************************************************************************************
	private function parseInput($input)
	{
		
		switch ($input)
		{
			case 'exit': return;
				break;
				
			case 'reg': echo $this->dumpRegistry();
				break;
				
			case 'cmd': echo Shell_Shell::getLatestInstance();
				break;
			
			case 'help': echo $this->help();
				break;
				
			default: echo "\nType 'help' to see the list of debug commands.\n\n";
				break; 
		}
		
	}
//******************************************************************************************************
	private function help()
	{
		$help =  "\n\nAvailable debug commands:\n\n"
				."\tcmd -- dump kohv shell commands.\n"
				."\texit -- leave this debug tool.\n"
				."\thelp -- display this help.\n"
				."\treg -- dump kohv system registry.\n"
				."\n\n";
				
		return $help;		
	}			

	
//******************************************************************************************************
	private function dumpRegistry()
	{
	  	$reg = Core_Registry::__toArray();
	  	
		// trying to make a table			
		$table = new Zend_Text_Table(array('columnWidths' => array(20, 60)));
		$table->setDecorator('ascii');
		$table->appendRow( array(' REG_KEY', ' VALUE') );

		foreach ($reg as $key => $value) 
		{
			$table->appendRow( array( ' '.(string)$key, ' '.(string)$value ) );			
		}
		
		return "\nSystem registry:\n" . $table->render();
	}	
	/*
	 

	*/

}